<template>
  <j-modal
    title="算法库"
    :width="1000"
    switchFullscreen
    :fullscreen="false"
    :draggable="true"
    :okButtonProps="{ class: { 'jee-hidden': true } }"
    @cancel="handleCancel"
    :cancelButtonProps="{ class: { 'jee-hidden': true } }"
    :visible="visible"
    :body-style="{ padding: '0px' }"
    class="ai-sfk-modal"
    centered
  >
    <a-card :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="">
                <j-input
                  placeholder="请输入算法名称"
                  style="background-color: #393939; border-color: #747474; color: #ddd"
                  v-model="queryParam.formulaName"
                ></j-input>
                <!-- <a-input-search placeholder="请输入算法名称"  enter-button="查询"  style="background-color: #393939; border-color: #747474;color:#ddd;" size="large" v-model="queryParam.formulaName" @search="searchQuery" />  -->
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 查询区域-END -->
      <div>
        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          class="j-table-force-nowrap"
          :scroll="{ x: true }"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          @change="handleTableChange"
        >
          <div slot="action" slot-scope="text, record">
            <a @click="handleRun(record)"> 运算 </a>
          </div>
          <span slot="formulaContent" slot-scope="text, record">
            <!-- {{ text.replaceAll('@','')}} -->
            <!-- style="max-width:1000px;white-space:normal; word-break:break-all;overflow:hidden;'" -->
            <div
              style="color: #ddd"
              v-html="
                record.formulaContentHtml.replaceAll(
                  'wise',
                  'span style=\'border: 1px solid #747474;font-size:14px;margin: 0 6px; padding:2px 5px;\''
                )
              "
            ></div>
          </span>
          <span slot="formulaNameAction" slot-scope="text, record">
            <a style="color: #ddd">{{ record.formulaName }}</a>
          </span>
        </a-table>
      </div>
    </a-card>
    <run-modal ref="runModal"></run-modal>
  </j-modal>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import RunModal from '@/views/corp/userFormula/run'
import store from '@/store/'
import '@/assets/less/TableExpand.less'

export default {
  name: 'UserFormulaList',
  mixins: [JeecgListMixin],
  components: {
    RunModal,
  },
  data() {
    return {
      description: '算法库',
      visible: false,
      // 表头
      columns: [
        // {
        //   title: '#',
        //   dataIndex: '',
        //   key: 'rowIndex',
        //   width: 60,
        //   align: 'center',
        //   customRender: function (t, r, index) {
        //     return parseInt(index) + 1
        //   },
        // },
        // {
        //   title: '算法ID',
        //   align: 'left',
        //   dataIndex: 'id',
        //   // fixed: 'left',
        //   width: 120,
        // },
        {
          title: '算法名称',
          align: 'left',
          // fixed: 'left',
          scopedSlots: { customRender: 'formulaNameAction' },
          // dataIndex: 'formulaName',
          // customRender: function (text) {
          //   return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          // },
        },
        {
          title: '内容',
          align: 'left',
          dataIndex: 'formulaContent',
          scopedSlots: { customRender: 'formulaContent' },
          // customRender: function (text) {
          //   return text.replaceAll('@','');
          // },
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
          customCell: this.readCustomCell,
        },
      ],
      url: {
        list: '/userFormula/userFormula/list',
        delete: '/userFormula/userFormula/delete',
        deleteBatch: '/userFormula/userFormula/deleteBatch',
        exportXlsUrl: '/userFormula/userFormula/exportXls',
        importExcelUrl: 'userFormula/userFormula/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
    userInfo() {
      return this.$store.getters.userInfo
    },
  },
  methods: {
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'formulaName', text: '公式名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'formulaContent', text: '内容', dictCode: '' })
      fieldList.push({ type: 'date', value: 'modifyDate', text: '修改日期' })
      fieldList.push({ type: 'string', value: 'remark', text: '备注', dictCode: '' })
      fieldList.push({ type: 'int', value: 'seqNo', text: '序号，用于公式排序', dictCode: '' })
      fieldList.push({ type: 'string', value: 'userId', text: '创建人', dictCode: '' })
      this.superFieldList = fieldList
    },
    show() {
      this.visible = true
    },
    handleCancel() {
      this.visible = false
    },
    handleRun: function (record) {
      this.$refs.runModal.show(record)
    },
    addModalFormOk(formulaId) {
      this.loadData()
      this.$refs.editModal.show(formulaId)
    },
    readCustomCell() {
      return {
        style: {
          // 行背景色
          'background-color': '#335',
          color: '#fff',
          cursor: 'pointer',
        },
      }
    },
  },
}
</script>
<style scoped lang="less">
@import '~@assets/less/common.less';
table:hover,
tr:hover,
thead:hover {
  background: #20293c !important;
}

.ai-sfk-modal {
  /deep/.ant-modal-content {
    background: transparent;
  }
  /deep/.ant-modal-footer {
    border: none;
  }
  /deep/.ant-modal-header,
  .ant-card,
  .ant-card-body {
    background-color: rgba(255, 255, 255, 0.2); /* 半透明背景 */
    backdrop-filter: blur(20px); /* 背景模糊 */
    -webkit-backdrop-filter: blur(10px); /* 兼容老版本 Safari */
    color: #ddd;
    border-bottom: 0px;
  }
  /deep/.ant-modal-title,
  /deep/.ant-modal-close {
    color: #ccc;
  }
  // /deep/.ant-modal-body {
  //   background-color: rgba(255, 255, 255, 0.2); /* 半透明背景 */
  //   backdrop-filter: blur(20px); /* 背景模糊 */
  //   -webkit-backdrop-filter: blur(10px); /* 兼容老版本 Safari */
  // }
  /deep/.ant-table-tbody > tr.ant-table-row:hover > td,
  .ant-table-tbody > tr > td.ant-table-cell-row-hover,
  .ant-table-row-hover {
    background: #336;
  }
  /deep/.ant-table {
    background-color: #4c4d4d;
    height: 507px;
  }
  /deep/.ant-table-middle
    > .ant-table-content
    > .ant-table-scroll
    > .ant-table-body
    > table
    > .ant-table-thead
    > tr
    > th {
    background-color: #393939;
    color: #ddd;
  }
  /deep/.ant-table-middle
    > .ant-table-content
    > .ant-table-fixed-right
    > .ant-table-body-outer
    > .ant-table-body-inner
    > table
    > .ant-table-thead
    > tr
    > th {
    background: #333;
    color: #ddd;
  }
  /deep/.ant-table-bordered .ant-table-thead > tr > th,
  .ant-table-bordered .ant-table-tbody > tr > td {
    border-color: #747474;
  }
  /deep/.ant-table-bordered .ant-table-body > table {
    border-color: #747474;
  }
  /deep/.ant-table-tbody > tr > td {
    border-color: #747474;
  }
  /deep/.ant-table-placeholder{
    background: transparent;
    border: none;
    .ant-empty-description{
       color: #ddd;
    }
  }
  
  /deep/.ant-pagination {
    color: #fff;
    .ant-pagination-item a {
      color: #fff;
    }
    .ant-pagination-item-active a {
      color: #1890ff;
    }
    .ant-pagination-item-link {
      background: #ccc;
    }
  }
}
</style>